package zuoy;

public class Task2 {
    public static void main(String[] args) {

        int[] oldArray = {2,3,5,5,0,0,1,6,0,5,4,7,6,9,0,0};
        int newArrayLength = getLenght(oldArray);
        int[] newArray = getNewArray(oldArray, newArrayLength);
        print(oldArray);
        print(newArray);
        getCha(oldArray, newArray);
    }
    public static int getLenght(int[] array){
        int num = 0;
        for(int i = 0 ; i < array.length;i++){
            if(array[i] != 0){
                num++;
            }
        }
        return num;
    }

    public static int[]  getNewArray(int[] array,int num){
        int[] newArray = new int[num];
        int index = 0;
        for(int i = 0; i < array.length; i ++){
            if(array[i]!=0){
                newArray[index] = array[i];
                index++;
            }
        }
        return newArray;
    }
    public static void print(int [] array){
        for(int i : array){
            System.out.print(i+" ");
        }
        System.out.println();
    }
    public static void getCha(int[] oldArray,int[] newArray){
        System.out.println("两个数组差"+(oldArray.length-newArray.length)+"个元素");
    }
}
